home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / !Interfaces / Universal Interfaces 2.0a1 / CIncludes / CodeFragments.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-17  |  6.6 KB  |  216 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        CodeFragments.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a1.  ETO #15, MPW prerelease.  Sunday, July 17, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16.  
  17. #ifndef __CODEFRAGMENTS__
  18. #define __CODEFRAGMENTS__
  19.  
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24. /*    #include <ConditionalMacros.h>                                */
  25.  
  26. #ifndef __FILES__
  27. #include <Files.h>
  28. #endif
  29. /*    #include <MixedMode.h>                                        */
  30. /*    #include <OSUtils.h>                                        */
  31.  
  32. #ifndef __TRAPS__
  33. #include <Traps.h>
  34. #endif
  35.  
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39.  
  40. #if GENERATINGPOWERPC
  41. #pragma options align=mac68k
  42. #endif
  43.  
  44. #ifdef __CFM68K__
  45. #pragma lib_export on
  46. #endif
  47.  
  48. typedef long ConnectionID;
  49.  
  50. typedef unsigned long LoadFlags;
  51.  
  52. typedef unsigned char SymClass;
  53.  
  54.  
  55. enum {
  56.     kPowerPCArch                = 'pwpc',                        /* use as the architecture type */
  57.     kMotorola68KArch            = 'm68k',                        /* use as the architecture type */
  58.     kAnyArchType                = 0x3f3f3f3f,
  59. /* Confusing names, soon to be removed! */
  60.     kPowerPC                    = 'pwpc',                        /* use as the architecture type */
  61.     kMotorola68K                = 'm68k',                        /* use as the architecture type */
  62.     kNoLibName                    = 0,
  63.     kNoConnectionID                = 0,
  64.     kUnresolvedSymbolAddress    = 0
  65. };
  66.  
  67. /* Constants used for findFlags mask */
  68. enum {
  69.     kLoadLib                    = 1,                            /* use existing connection if possible */
  70.     kFindLib                    = 2,                            /* just see if library is already loaded */
  71.     kLoadNewCopy                = 5,                            /* load a new instance no matter what */
  72.     kUseInPlace                    = 0x80                            /* use container’s sections in place */
  73. };
  74.  
  75. enum {
  76.     kCodeSym                    = 0,
  77.     kDataSym                    = 1,
  78.     kTVectSym                    = 2,
  79.     kTOCSym                        = 3,
  80.     kGlueSym                    = 4
  81. };
  82.  
  83. /*    Constants for the FragmentLocator field .where (other values for this enum exist) */
  84. enum {
  85.     kInMem                        = 0,
  86.     kOnDiskFlat                    = 1,
  87.     kOnDiskSegmented            = 2
  88. };
  89.  
  90. #define IsFileLocation(where) (((where) == kOnDiskFlat) || ((where) == kOnDiskSegmented))
  91. enum {
  92.     kIsLib                        = 0,
  93.     kIsApp                        = 1,
  94.     kIsDropIn                    = 2
  95. };
  96.  
  97. /*    Constants for the 'cfrg' field .updateLevel */
  98. enum {
  99.     kFullLib                    = 0,
  100.     kUpdateLib                    = 1
  101. };
  102.  
  103. /* For fragment initialization routines */
  104. struct MemFragment {
  105.     Ptr                                address;
  106.     long                            length;
  107.     Boolean                            inPlace;
  108.     char                            spare3a[3];
  109. };
  110. typedef struct MemFragment MemFragment;
  111.  
  112. struct DiskFragment {
  113.     FSSpecPtr                        fileSpec;                    /* Must correspond to FSSpecPtr in segmented case */
  114.     long                            offset;
  115.     long                            length;
  116. };
  117. typedef struct DiskFragment DiskFragment;
  118.  
  119. struct SegmentedFragment {
  120.     FSSpecPtr                        fileSpec;                    /* Must correspond to FSSpecPtr in data fork case */
  121.     OSType                            rsrcType;
  122.     short                            rsrcID;
  123. };
  124. typedef struct SegmentedFragment SegmentedFragment;
  125.  
  126. /* Note that the onDisk and inSegs members are required to have an FSSpecPtr
  127.  field at the same location.  CFM code uses just one member to access the
  128.  information for either case */
  129. struct FragmentLocator {
  130.     long                            where;
  131.     union {
  132.         MemFragment                        inMem;
  133.         DiskFragment                    onDisk;
  134.         SegmentedFragment                inSegs;
  135.     } u;
  136. };
  137.  
  138. typedef struct FragmentLocator FragmentLocator, *FragmentLocatorPtr;
  139.  
  140. /* NOTE: when fragLocator. where == kOnDisk, then
  141.        fragLocator. u. onDisk. fileSpec is a pointer
  142.        to the file that the library belonged to.
  143.        the pointer is valid only for the duration
  144.        of the init routine's invocation, so make
  145.        a copy of the filespec if it is important */
  146. struct InitBlock {
  147.     long                            contextID;
  148.     long                            closureID;
  149.     long                            connectionID;
  150.     FragmentLocator                    fragLocator;
  151.     Ptr                                libName;
  152.     long                            reserved4a;
  153.     long                            reserved4b;
  154.     long                            reserved4c;
  155.     long                            reserved4d;
  156. };
  157. typedef struct InitBlock InitBlock, *InitBlockPtr;
  158.  
  159. /* Prototype for initialization routines.  Note that these are C, not Pascal conventions!
  160.  This differs from customary “Apple-callback” useage, but is felt to be less error prone
  161.  in practice since the vast bulk of 68K CFM aware code will be in C.
  162.  NOTE: Initialization routines may comfortably ignore their parameters, however, they must
  163.  return an error status (ie: noErr) in order to succeed with the load of the library.
  164.  Termination routines get no parameters and have no return value. */
  165. typedef OSErr ConnectionInitializationRoutine(InitBlockPtr initBlkPtr);
  166. typedef void ConnectionTerminationRoutine(void);
  167. /* Constants used in building shared libraries */
  168.  
  169. enum {
  170.     kCFMRsrcType                = 'cfrg',
  171.     kCFMRsrcID                    = 0,
  172.     kSHLBFileType                = 'shlb'
  173. };
  174.  
  175. #ifndef TurnOff68KCFMTraps
  176. #define TurnOff68KCFMTraps 0
  177. #endif
  178. #if TurnOff68KCFMTraps
  179. extern pascal OSErr GetSharedLibrary(Str63 libName, OSType archType, LoadFlags findFlags, ConnectionID *connID, Ptr *mainAddr, Str255 errName);
  180. extern pascal OSErr GetDiskFragment(const FSSpec *fileSpec, long offset, long length, Str63 fragName, LoadFlags findFlags, ConnectionID *connID, Ptr *mainAddr, Str255 errName);
  181. extern pascal OSErr GetMemFragment(void *memAddr, long length, Str63 fragName, LoadFlags findFlags, ConnectionID *connID, Ptr *mainAddr, Str255 errName);
  182. extern pascal OSErr CloseConnection(ConnectionID *connID);
  183. extern pascal OSErr FindSymbol(ConnectionID connID, Str255 symName, Ptr *symAddr, SymClass *symClass);
  184. extern pascal OSErr CountSymbols(ConnectionID connID, long *symCount);
  185. extern pascal OSErr GetIndSymbol(ConnectionID connID, long symIndex, Str255 symName, Ptr *symAddr, SymClass *symClass);
  186. #else
  187. extern pascal OSErr GetSharedLibrary(Str63 libName, OSType archType, LoadFlags findFlags, ConnectionID *connID, Ptr *mainAddr, Str255 errName)
  188.  THREEWORDINLINE(0x3F3C, 1, 0xAA5A);
  189. extern pascal OSErr GetDiskFragment(const FSSpec *fileSpec, long offset, long length, Str63 fragName, LoadFlags findFlags, ConnectionID *connID, Ptr *mainAddr, Str255 errName)
  190.  THREEWORDINLINE(0x3F3C, 2, 0xAA5A);
  191. extern pascal OSErr GetMemFragment(void *memAddr, long length, Str63 fragName, LoadFlags findFlags, ConnectionID *connID, Ptr *mainAddr, Str255 errName)
  192.  THREEWORDINLINE(0x3F3C, 3, 0xAA5A);
  193. extern pascal OSErr CloseConnection(ConnectionID *connID)
  194.  THREEWORDINLINE(0x3F3C, 4, 0xAA5A);
  195. extern pascal OSErr FindSymbol(ConnectionID connID, Str255 symName, Ptr *symAddr, SymClass *symClass)
  196.  THREEWORDINLINE(0x3F3C, 5, 0xAA5A);
  197. extern pascal OSErr CountSymbols(ConnectionID connID, long *symCount)
  198.  THREEWORDINLINE(0x3F3C, 6, 0xAA5A);
  199. extern pascal OSErr GetIndSymbol(ConnectionID connID, long symIndex, Str255 symName, Ptr *symAddr, SymClass *symClass)
  200.  THREEWORDINLINE(0x3F3C, 7, 0xAA5A);
  201. #endif
  202.  
  203. #ifdef __CFM68K__
  204. #pragma lib_export off
  205. #endif
  206.  
  207. #if GENERATINGPOWERPC
  208. #pragma options align=reset
  209. #endif
  210.  
  211. #ifdef __cplusplus
  212. }
  213. #endif
  214.  
  215. #endif /* __CODEFRAGMENTS__ */
  216.